Skip to content

impr(polyglot): Add new structure (wordsMap) to PolyglotWordset to get words from any language by uniform distribution (@IliyaZinoviev)#7440

Open
IliyaZinoviev wants to merge 1 commit intomonkeytypegame:masterfrom
IliyaZinoviev:feature/balanced-polyglot-v3
Open

impr(polyglot): Add new structure (wordsMap) to PolyglotWordset to get words from any language by uniform distribution (@IliyaZinoviev)#7440
IliyaZinoviev wants to merge 1 commit intomonkeytypegame:masterfrom
IliyaZinoviev:feature/balanced-polyglot-v3

Conversation

@IliyaZinoviev
Copy link

@IliyaZinoviev IliyaZinoviev commented Jan 24, 2026

Add uniform distribution to polyglot

Motivation

During polyglot using, I mentioned that words from language with huge dictionaries are met always, but words from small one - never (at least from a user experience perspective, it looks like this). My PR solves this issue. And now each language is consumed per test as much as any other.

Description

Changed:

  • PolyglotWordset class
  • places in files where PolyglotWordset is used:
    • words-generator.ts
    • funbox-functions.ts .

Checks

  • Adding quotes?
    • Make sure to include translations for the quotes in the description (or another comment) so we can verify their content.
  • Adding a language?
    • Make sure to follow the languages documentation
    • Add language to packages/schemas/src/languages.ts
    • Add language to exactly one group in frontend/src/ts/constants/languages.ts
    • Add language json file to frontend/static/languages
  • Adding a theme?
    • Make sure to follow the themes documentation
    • Add theme to packages/schemas/src/themes.ts
    • Add theme to frontend/src/ts/constants/themes.ts
    • (optional) Add theme css file to frontend/static/themes
    • Add some screenshots of the theme, especially with different test settings (colorful, flip colors) to your pull request
  • Adding a layout?
    • Make sure to follow the layouts documentation
    • Add layout to packages/schemas/src/layouts.ts
    • Add layout json file to frontend/static/layouts
  • Adding a font?
    • Make sure to follow the fonts documentation
    • Add font file to frontend/static/webfonts
    • Add font to packages/schemas/src/fonts.ts
    • Add font to frontend/src/ts/constants/fonts.ts
  • Check if any open issues are related to this PR; if so, be sure to tag them below.
  • Make sure the PR title follows the Conventional Commits standard. (https://www.conventionalcommits.org for more info)
  • Make sure to include your GitHub username prefixed with @ inside parentheses at the end of the PR title.

Closes #

@monkeytypegeorge monkeytypegeorge added the frontend User interface or web stuff label Jan 24, 2026
@IliyaZinoviev IliyaZinoviev changed the title impr(polyglot): Add new structure (wordsMap) to PolyglotWordset to get words from any language by uniform distribution impr(polyglot): Add new structure (wordsMap) to PolyglotWordset to get words from any language by uniform distribution (@IliyaZinoviev) Jan 24, 2026
@IliyaZinoviev IliyaZinoviev force-pushed the feature/balanced-polyglot-v3 branch 2 times, most recently from 2d5e9ad to ed49d47 Compare January 24, 2026 14:18
@IliyaZinoviev IliyaZinoviev force-pushed the feature/balanced-polyglot-v3 branch from ed49d47 to 52be7ba Compare January 27, 2026 06:56
@Miodec Miodec requested a review from Copilot February 27, 2026 14:01
@github-actions github-actions bot added the waiting for review Pull requests that require a review before continuing label Feb 27, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adjusts polyglot word generation so languages are sampled (approximately) uniformly, rather than being dominated by languages with larger dictionaries.

Changes:

  • Refactors PolyglotWordset to store per-language Wordsets (wordsMap) and pick a language uniformly per generated word.
  • Updates word generation logic to use PolyglotWordset.currentLanguage instead of per-word language lookups.
  • Small control-flow cleanup in word list retrieval / funbox wordset assignment.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
frontend/src/ts/test/words-generator.ts Switches polyglot language detection to currentLanguage; minor cleanup around word list returns and funbox wordset assignment.
frontend/src/ts/test/funbox/funbox-functions.ts Reworks PolyglotWordset internals to use wordsMap and uniform language selection.

Comment on lines +158 to +166
super([]);
this.languageProperties = languageProperties;
this.langs = Array.from(languageProperties.keys());
this.wordsMap = wordsMap;
this.resetIndexes();
this.length = Array.from(this.wordsMap.values()).reduce(
(sum, ws) => sum + ws.words.length,
0,
);
Copy link

Copilot AI Feb 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PolyglotWordset now calls super([]) and never populates this.words. Code in words-generator relies on currentWordset.words (eg repeat-quote path + hasTab/hasNewline checks), so polyglot wordsets will report an empty list. Consider keeping words as an aggregate of all per-language words (or overriding/adding an accessor and updating consumers to use it).

Suggested change
super([]);
this.languageProperties = languageProperties;
this.langs = Array.from(languageProperties.keys());
this.wordsMap = wordsMap;
this.resetIndexes();
this.length = Array.from(this.wordsMap.values()).reduce(
(sum, ws) => sum + ws.words.length,
0,
);
const aggregatedWords = Array.from(wordsMap.values()).reduce<string[]>(
(all, ws) => all.concat(ws.words),
[],
);
super(aggregatedWords);
this.languageProperties = languageProperties;
this.langs = Array.from(languageProperties.keys());
this.wordsMap = wordsMap;
this.resetIndexes();
this.length = aggregatedWords.length;

Copilot uses AI. Check for mistakes.
}

override resetIndexes(): void {
this.wordsMap.forEach((ws, _) => {
Copy link

Copilot AI Feb 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resetIndexes() uses this.wordsMap.forEach((ws, _) => ...) but the key param is unused. Drop the second arg to avoid unused-var lint noise.

Suggested change
this.wordsMap.forEach((ws, _) => {
this.wordsMap.forEach(ws => {

Copilot uses AI. Check for mistakes.
@Miodec Miodec added waiting for update Pull requests or issues that require changes/comments before continuing and removed waiting for review Pull requests that require a review before continuing labels Feb 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

frontend User interface or web stuff waiting for update Pull requests or issues that require changes/comments before continuing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants